package edu.gatech.coc.sirana.graph;

import java.util.ArrayList;

import net.util.Debug;

import edu.gatech.coc.sirana.parser.ClientLogItem;

/**
 * 
 * @author Paul
 *
 */
public class SRCycles {
	/**
	 * A SRCycle contains successive repeated cycles.
	 * By successive, it means a cycle's tail item is next to another cycle's head item.
	 * By repeated, it means two cycles have the same back-edge (i.e., the action of head item and the action of tail item)
	 */
	
	ArrayList<InteractionCycle> cycles;

	public SRCycles(ArrayList<InteractionCycle> c){
		this.setCycles(c);
	}
	
	public String findIDSequence(){
		InteractionCycle ic = this.findCharactorCycle();
		StringBuffer IDSeq = new StringBuffer();
//		Debug.println("----CharactorCycle:" + ic.toString());
		for (ClientLogItem item : ic.getItems()){			
			IDSeq.append( item.findIDString() + "," );
		}
//		Debug.println( "IDSeq: " + IDSeq );
//		Debug.println("----");
		return IDSeq.toString().substring(0, IDSeq.length()-1);
	}
	
	public InteractionCycle findCharactorCycle(){
		return this.getCycles().get(0);
	}
	
	public String findCharactorActionString(){
		ArrayList<String> actions = this.findCharactorCycle().findAllAction();
		StringBuffer sb = new StringBuffer();
		
		for (String a: actions){
			sb.append(a + "\n");
		}
		
		return sb.toString();
	}
	
	public ArrayList<InteractionCycle> getCycles() {
		return cycles;
	}

	public void setCycles(ArrayList<InteractionCycle> circles) {
		this.cycles = circles;
	}
	
	public String toIdString(){
		StringBuffer sb	= new StringBuffer();
		
		for (InteractionCycle c: this.cycles){
			sb.append("----Circle: \n\t" + c.findItemIds() + "\n");
		}
		
		return sb.toString(); 
	}
	public String toString(){
		StringBuffer sb	= new StringBuffer();
		
		for (InteractionCycle c: this.cycles){
			sb.append("----Circle: \n\t" + c.toString() + "\n");
		}
		
		return sb.toString();
	}
}
